import store from '@/store/index'
import request from '@/utils/request'

export function getData(url, method, params) {
  // 参数
  return request({
    url: url,
    method: method,
    params
  })
}

export function postData(url, dataJson, token) {
  token = store.state.user.token
  const date = JSON.stringify(dataJson)
  // date = encodeURIComponent(date)
  const params = { 'token': token, 'data': date }
  // 参数
  return request({
    url: url,
    method: 'post',
    data: params
  })
}

// 获取树菜单
export function getMenu(userCode, token) {
  const params = { 'userCode': userCode, 'token': token }
  return request({
    url: '/testMenuManager/getMenu',
    method: 'get',
    params
  })
}

// 获取标题菜单
export function getTab(userCode, token) {
  const params = { 'userCode': userCode, 'token': token }
  return request({
    url: '/testMenuManager/getTab',
    method: 'get',
    params
  })
}

// 获取正式环境 - 菜单树
export function getMenuTree(userCode, token) {
  // 参数
  return getData('/kams/menu/fi_getTreeMenu', 'get', {
    token: token,
    userCode: userCode
  })
}

// 获取菜单权限
export function getMenuAuth(menuCode, roleCode, token) {
  return getData('/kams/menu/fi_getAuthMenuFunByRole', 'get',
    {
      token: token,
      menuCode: menuCode,
      roleCode: roleCode
    }
  )
}
